﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Base;

namespace ConsoleApp.Test
{
    internal class TestObjectEx
    {
        public static void Test()
        {
            //char ch = '张';
            //var value1 = (sbyte)ch;
            //var value2 = (byte)ch;
            //var value3 = (Int16)ch;
            //var value4 = (UInt16)ch;
            //var value5 = (Int32)ch;
            //var value6 = (UInt32)ch;
            //var value7 = (Int64)ch;
            //var value8 = (UInt64)ch;
            //var value9 = (Single)ch;
            //var value10 = (double)ch;
            //var value11 = (decimal)ch;
            //var value12 = (bool)((int)ch);
            //var value13 = (DateTime)ch;

            //char ch = (char)(byte.MaxValue);

            char ch = '张';

            Console.WriteLine("******************* char ******************************");
            Case(ch, ch);
            Case(ch, (sbyte)1);
            Case(ch, (byte)1);
            Case(ch, (short)1);
            Case(ch, (ushort)1);
            Case(ch, (int)ch);
            Case(ch, (uint)ch);
            Case(ch, (long)1);
            Case(ch, (ulong)1);
            Case(ch, (float)1);
            Case(ch, (double)1);
            Case(ch, (decimal)1);

            Console.WriteLine("******************* sbyte ******************************");
            sbyte sbyteValue = -1;
            Case(sbyteValue, ch);
            Case(sbyteValue, (sbyte)1);
            Case(sbyteValue, (byte)1);
            Case(sbyteValue, (short)1);
            Case(sbyteValue, (ushort)1);
            Case(sbyteValue, (int)ch);
            Case(sbyteValue, (uint)ch);
            Case(sbyteValue, (long)1);
            Case(sbyteValue, (ulong)1);
            Case(sbyteValue, (float)1);
            Case(sbyteValue, (double)1);
            Case(sbyteValue, (decimal)1);

            Console.WriteLine("******************* byte ******************************");
            byte byteValue = 1;
            Case(byteValue, ch);
            Case(byteValue, (sbyte)1);
            Case(byteValue, (byte)1);
            Case(byteValue, (short)1);
            Case(byteValue, (ushort)1);
            Case(byteValue, (int)ch);
            Case(byteValue, (uint)ch);
            Case(byteValue, (long)1);
            Case(byteValue, (ulong)1);
            Case(byteValue, (float)1);
            Case(byteValue, (double)1);
            Case(byteValue, (decimal)1);

            Console.WriteLine("******************* short ******************************");
            short shortValue = -1;
            Case(shortValue, ch);
            Case(shortValue, (sbyte)1);
            Case(shortValue, (byte)1);
            Case(shortValue, (short)1);
            Case(shortValue, (ushort)1);
            Case(shortValue, (int)ch);
            Case(shortValue, (uint)ch);
            Case(shortValue, (long)1);
            Case(shortValue, (ulong)1);
            Case(shortValue, (float)1);
            Case(shortValue, (double)1);
            Case(shortValue, (decimal)1);

            Console.WriteLine("******************* ushort ******************************");
            ushort ushortValue = 1;
            Case(ushortValue, ch);
            Case(ushortValue, (sbyte)1);
            Case(ushortValue, (byte)1);
            Case(ushortValue, (short)1);
            Case(ushortValue, (ushort)1);
            Case(ushortValue, (int)ch);
            Case(ushortValue, (uint)ch);
            Case(ushortValue, (long)1);
            Case(ushortValue, (ulong)1);
            Case(ushortValue, (float)1);
            Case(ushortValue, (double)1);
            Case(ushortValue, (decimal)1);

            Console.WriteLine("******************* int ******************************");
            int intValue = -1;
            Case(intValue, ch);
            Case(intValue, (sbyte)1);
            Case(intValue, (byte)1);
            Case(intValue, (short)1);
            Case(intValue, (ushort)1);
            Case(intValue, (int)ch);
            Case(intValue, (uint)ch);
            Case(intValue, (long)1);
            Case(intValue, (ulong)1);
            Case(intValue, (float)1);
            Case(intValue, (double)1);
            Case(intValue, (decimal)1);

            Console.WriteLine("******************* uint ******************************");
            uint uintValue = 1;
            Case(uintValue, ch);
            Case(uintValue, (sbyte)1);
            Case(uintValue, (byte)1);
            Case(uintValue, (short)1);
            Case(uintValue, (ushort)1);
            Case(uintValue, (int)ch);
            Case(uintValue, (uint)ch);
            Case(uintValue, (long)1);
            Case(uintValue, (ulong)1);
            Case(uintValue, (float)1);
            Case(uintValue, (double)1);
            Case(uintValue, (decimal)1);

            Console.WriteLine("******************* long ******************************");
            long longValue = -1;
            Case(longValue, ch);
            Case(longValue, (sbyte)1);
            Case(longValue, (byte)1);
            Case(longValue, (short)1);
            Case(longValue, (ushort)1);
            Case(longValue, (int)ch);
            Case(longValue, (uint)ch);
            Case(longValue, (long)1);
            Case(longValue, (ulong)1);
            Case(longValue, (float)1);
            Case(longValue, (double)1);
            Case(longValue, (decimal)1);

            Console.WriteLine("******************* ulong ******************************");
            ulong ulongValue = 1;
            Case(ulongValue, ch);
            Case(ulongValue, (sbyte)1);
            Case(ulongValue, (byte)1);
            Case(ulongValue, (short)1);
            Case(ulongValue, (ushort)1);
            Case(ulongValue, (int)ch);
            Case(ulongValue, (uint)ch);
            Case(ulongValue, (long)1);
            Case(ulongValue, (ulong)1);
            Case(ulongValue, (float)1);
            Case(ulongValue, (double)1);
            Case(ulongValue, (decimal)1);

            Console.WriteLine("******************* float ******************************");
            float floatValue = 1.0f;
            Case(floatValue, ch);
            Case(floatValue, (sbyte)1);
            Case(floatValue, (byte)1);
            Case(floatValue, (short)1);
            Case(floatValue, (ushort)1);
            Case(floatValue, (int)ch);
            Case(floatValue, (uint)ch);
            Case(floatValue, (long)1);
            Case(floatValue, (ulong)1);
            Case(floatValue, (float)1);
            Case(floatValue, (double)1);
            Case(floatValue, (decimal)1);

            Console.WriteLine("******************* double ******************************");
            double doubleValue = 1.0d;
            Case(doubleValue, ch);
            Case(doubleValue, (sbyte)1);
            Case(doubleValue, (byte)1);
            Case(doubleValue, (short)1);
            Case(doubleValue, (ushort)1);
            Case(doubleValue, (int)ch);
            Case(doubleValue, (uint)ch);
            Case(doubleValue, (long)1);
            Case(doubleValue, (ulong)1);
            Case(doubleValue, (float)1);
            Case(doubleValue, (double)1);
            Case(doubleValue, (decimal)1);

            Console.WriteLine("******************* decimal ******************************");
            decimal decimalValue = 1.0m;
            Case(decimalValue, ch);
            Case(decimalValue, (sbyte)1);
            Case(decimalValue, (byte)1);
            Case(decimalValue, (short)1);
            Case(decimalValue, (ushort)1);
            Case(decimalValue, (int)ch);
            Case(decimalValue, (uint)ch);
            Case(decimalValue, (long)1);
            Case(decimalValue, (ulong)1);
            Case(decimalValue, (float)1);
            Case(decimalValue, (double)1);
            Case(decimalValue, (decimal)1);


            Console.WriteLine("******************* end ******************************");
        }

        private static void Case(object objA, object objB)
        {
            string typeNameA = objA != null ? objA.GetType().Name : "null";
            string typeNameB = objB != null ? objB.GetType().Name : "null";
            string retStr = ObjectEx.EqualsEx(objA, objB) ? "相等" : "不等";
            Console.WriteLine($"{objA}({typeNameA}) {objB}({typeNameB})     结果:{retStr}");

        }

    }
}
